package com.mall4j.cloud.product.repository;

import com.mall4j.cloud.product.model.Spu;
import com.mall4j.cloud.product.model.SpuHistory;
//import org.apache.ibatis.annotations.Param;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import java.util.List;

public interface SpuRepository extends JpaRepository<SpuHistory, Long> {
    @Query(value = "SELECT DISTINCT spu_id, `name`, main_img_url, price_fee, browse_history.create_time FROM spu INNER JOIN browse_history ON spu.spu_id = browse_history.product_id WHERE browse_history.user_id = (:userId) ORDER BY browse_history.create_time DESC" ,nativeQuery = true)
    List<SpuHistory> findSpuHistory(@Param("userId") Long userId);
}
